<template>
  <el-dialog
    title="新增"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
<!--      <el-form-item label="选择库">
        <el-select placeholder="待补充">
          <el-option></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="选择表">
        <el-select placeholder="待补充">
          <el-option></el-option>
        </el-select>
      </el-form-item>-->
      <el-form-item label="选择指标" prop="zbCode">
        <el-select v-model="dataForm.zbCode">
         <el-option v-for="item in zbData" :key="item.zbCode" :label="item.zbName" :value="item.zbCode"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="监控等级" prop="zbLevel">
        <el-select v-model="dataForm.zbLevel">
          <el-option key="2001" label="每日推送" value="2001"></el-option>
          <el-option key="2002" label="实时可查" value="2002"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input type="textarea" v-model="dataForm.remark" placeholder="备注"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import API from '@/api'
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            zbCode: '',
            zbLevel: '',
            remark: ''
          },
          zbData: []
        }
      },
      methods: {
        init () {
          API.zbconfig.zb().then(({data}) => {
            this.zbData = data
          })
          this.visible = true
        },
        dataFormSubmit () {
          var params = {
            'zbCode': this.dataForm.zbCode,
            'zbLevel': this.dataForm.zbLevel,
            'creator': this.$store.state.user.name,
            'remark': this.dataForm.remark
          }
          var tick = API.zbconfig.add(params)
          tick.then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      }
    }
</script>

<style scoped>

</style>
